﻿using System;
using SilverQuery;

namespace SilverQueryDemo
{
	public class EventSamples : SilverQueryComponent
	{
		public override void ready()
		{
			@q("#outerDiv").click(e =>
			{
				@q("#result1").html("currentTarget: " + @q(e.currentTarget).attr("id") + ", target:" + @q(e.target).attr("id"));
				return false;
			});

			@q("#keyDownDemo input[type='text']").keydown(e =>
			{
				// Remove focus when the enter key is pressed.
				if (e.keyCode == 13)
				{
					@q(e.currentTarget).blur();
					@q("#keyDownDemo div.output").html("Enter key pressed.");
				}
				return true;
			});

			EventCallback clickCallback = (e)=> { @q("#unbindDemo span").html("Event triggered at " + DateTime.Now.ToString()); return false; };
			
			@q("#unbindDemo input[value='Bind']").click(e=> 
			{ 
				@q("#unbindDemo input[value='Trigger']").click(clickCallback); return false; 
			});

			@q("#unbindDemo input[value='Unbind']").click(e =>
			{
				@q("#unbindDemo input[value='Trigger']").unbind("click", clickCallback); return false;
			});
		}
	}
}
